Skip to content

Fix greenlet re-entry wakeups and closed transport protocol leaks - #117

Merged
egorsmkv merged 2 commits into
masterfrom
fix/greenlet-reentry-transport-lifetimes
Oct 10, 2026
Merged

egorsmkv merged 2 commits into
masterfrom
fix/greenlet-reentry-transport-lifetimes

Conversation

@egorsmkv

Copy link
Copy Markdown
Contributor

A greenlet resumed during a later loop run can temporarily replace the C stack containing the active ready queue. Allocate that queue on the heap so call_soon always writes to stable storage. This restores lock wakeups and task cancellation when startup and serving enter the loop at different C stack depths.

After connection_lost, stream transports now release their protocol, cached bound methods, fast-reader references and saved context. Subprocess transports release their protocol/context too. Cleanup runs even when the callback raises, and Python references are dropped outside state locks so finalizers can reenter safely. Stream get_protocol() returns None after teardown; socket extra-info behavior is preserved.

Add 21 regression cases: six stack depths with the minimal and SQLAlchemy greenlet bridges; connection churn with close, abort and peer disconnect, including callback failures; StreamReaderProtocol fast-path ownership; and subprocess protocol ownership. Document the scope and reproduction commands.

Validation on Linux / CPython 3.14.7:

  • Before fixes: 13 of the initial 19 regression cases failed (stream retention and deeper greenlet wakeups); both additional subprocess lifetime cases also failed.
  • After fixes: all 21 regression cases passed.
  • Ecosystem suite: 78 passed, 36 PostgreSQL cases skipped because no database service was available locally.
  • Core Python suite: 484 passed, 101 skipped; two Unix-domain socket tests were blocked by sandbox PermissionError (EPERM).
  • Rust suite: 331 passed; 15 io_uring/Unix-socket tests were blocked by sandbox EPERM.
  • cargo clippy --all-targets --all-features --locked -- -D warnings, cargo fmt --check, and Ruff checks passed.

End-to-end Granian/PostgreSQL load and shutdown behavior was not tested locally; CI supplies the OS/Python and PostgreSQL coverage.

Fixes #115
Fixes #116

@egorsmkv
egorsmkv merged commit bcbc3f6 into master Oct 10, 2026
46 checks passed
@egorsmkv
egorsmkv deleted the fix/greenlet-reentry-transport-lifetimes branch October 10, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant